package com.iss.airsys.controller;
import com.iss.airsys.config.PrereadConfig;
import com.iss.airsys.entity.FixAssets;
import com.iss.airsys.config.MyWebConfigurer;
import com.iss.airsys.model.MyResponseData;
import com.iss.airsys.service.FixAssetsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@RestController
@RequestMapping("fixAssets/")
public class FixAssetsController {
    private int  count=-1;

    @Autowired
    FixAssetsService service;

    @RequestMapping("insertfixAssets")
    public MyResponseData insertfixAssets(FixAssets fixAssets){
        MyResponseData responseData = new MyResponseData();
        count=service.insertfixAssets(fixAssets);
        if (count > 0) {
            responseData.setErrorCode(0);
            responseData.setStatus("添加成功");
        } else {
            responseData.setErrorCode(-1);
            responseData.setStatus("添加失败");
        }
        return responseData;
    }
    @RequestMapping("selectAllfixAssets")
    public List<FixAssets> selectAllfixAssets(){
        List<FixAssets> assets = service.selectAllfixAssets();
        System.out.println(assets);
       return assets;
    }
    @RequestMapping("deletefixAssets")
    public MyResponseData deletefixAssets(Integer[] assets_ids){
        MyResponseData responseData = new MyResponseData();
        count=service.deletefixAssets(assets_ids);
        if (count > 0) {
            responseData.setErrorCode(0);
            responseData.setStatus("成功");
        } else {
            responseData.setErrorCode(-1);
            responseData.setStatus("失败");
        }
        return responseData;

    }
    @RequestMapping("updatefixAssets")
    public MyResponseData updatefixAssets(FixAssets fixAssets){
        MyResponseData responseData = new MyResponseData();
        count=service.updatefixAssets(fixAssets);
        if (count > 0) {
            responseData.setErrorCode(0);
            responseData.setStatus("成功");
        } else {
            responseData.setErrorCode(-1);
            responseData.setStatus("失败");
        }
        return responseData;
    }
    @RequestMapping("selectfixAssetsById")
    public MyResponseData selectfixAssetsById(Integer assets_id){

        MyResponseData responseData = new MyResponseData();
        FixAssets fixAssets=service.selectfixAssetsById(assets_id);
        if (fixAssets!=null) {
            responseData.setErrorCode(0);
            responseData.setObject(fixAssets);
            responseData.setStatus("成功");
        } else {
            responseData.setErrorCode(-1);
            responseData.setStatus("失败");
        }
        return responseData;
    }























}
